<template>
  <div class="home-1">
    <div class="home-1-content">
      <div class="guanai-1" @click="guadd" :class="{ iocs: flags }">
        <van-icon name="like" v-if="flags" color="red" />
        <van-icon name="like-o" v-else />
        {{ flags ? '标准版' : '关爱版' }}
      </div>
      <van-swipe lazy-render :show-indicators="false">
        <van-swipe-item v-for="(item, index) in images" :key="index">
          <img :src="item.img" class="home-1-img" />
        </van-swipe-item>
      </van-swipe>

      <div class="homes-lfti">
        <div class="xins-1">
          {{
            flag
              ? store.user?.user.nickName
              : `**${store.user?.user.nickName.charAt(store.user?.user.nickName.length - 1)}`
          }}<img :src="flag ? k : b" @click="flag = !flag" />
        </div>
        <div class="xu-1" @click="qadd">
          {{ fieldValue }}<van-icon name="arrow-down" />
        </div>
      </div>
      <div class="homes-xue" @click="xsadd">{{ xename }}</div>
      <div class="home-1-co1">
        <CpRadioBtn title="常用服务" @cadd="zjadd"></CpRadioBtn>

        <div class="home-1-co3">
          <div
            class="home-1-co4"
            v-for="(item, index) in arr"
            :key="index"
            @click="add(item)"
          >
            <img :src="item.iconUrl" class="imgs-1" />
            <div class="home-1-co5">{{ item.appName }}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 内容 -->
    <div class="home-12">
      <div class="gon-1">
        <div class="gon-1-1" @click="gadd"></div>
        <div class="gon-1-2" @click="gsadd">{{ gogao.noticeTitle }}</div>
      </div>
      <div class="home-banner">
        <van-swipe indicator-color="#fff">
          <van-swipe-item v-for="(item, index) in gimg" :key="index">
            <img :src="item.recImg" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="xue-1">
        <div class="xue-12 pg-1" @click="addurl">
          <div class="x-1">学校简历</div>
          <div class="x-2">校园风采</div>
        </div>
        <div class="xue-12 pg-2" @click="zaddurl">
          <div class="x-1">专业介绍</div>
          <div class="x-2">专业亮点</div>
        </div>
      </div>
      <div class="tuijian-1">
        <CpRadioBtn title="推荐服务" @cadd="zjadd"></CpRadioBtn>

        <div
          class="t-2"
          v-for="(item, index) in tjarr"
          :key="index"
          @click="tadd(item)"
        >
          <img :src="item.iconUrl" class="img-1s" />
          <div class="te-1">
            <div class="te-2">{{ item.appName }}</div>
            <div class="te-3">{{ item.constructionUnit }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <van-popup v-model:show="showPicker" round position="bottom">
    <van-picker
      :columns="columns"
      @cancel="showPicker = false"
      @confirm="onConfirm"
    />
  </van-popup>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router'
import { ref, onMounted } from 'vue'
import { getCommon } from '@/utils/Commonmethod'
import {
  getNotice,
  getSystemInfo,
  getCommonService,
  getRecommendService,
  getNoticeImg,
  getSchoolInfo
} from '@/services/user'
import { useUserStore, useComtokenStore, useListStore } from '@/stores'
import k from '@/assets/home/ic_view.png'
import b from '@/assets/home/ic_hide.png'
const arr: any = ref([])
const tjarr: any = ref([])
const images: any = ref([])
const gimg: any = ref([])
const store = useUserStore()
const sttokne = useComtokenStore()
const setList = useListStore()
const showPicker = ref(false)
const columns = [
  { text: '学生', value: '1' },
  { text: '教师', value: '2' },
  { text: '家长', value: '3' },
  { text: '社会学习者', value: '4' }
]
const fieldValue = ref('请选择')
const onConfirm = ({ selectedOptions }: any) => {
  showPicker.value = false
  fieldValue.value = selectedOptions[0].text
  if (fieldValue.value == '学生') {
    xueadd()
  }
}
const xename: any = ref('学在农林')
const gogao: any = ref({
  noticeTitle: '',
  noticeUrl: ''
})
const flag = ref(false)
const flags = ref(false)
const router = useRouter()
const yobj: any = ref({
  pageNum: 1,
  pageSize: 8
})
const tjobj: any = ref({
  pageNum: 1,
  pageSize: 2
})
const jlobj: any = ref({
  briefUrl: '',
  majorUrl: ''
})
const add = (item: any) => {
  getCommon({
    monitorType: 'app',
    monitorId: item.appId,
    monitorStatus: '1'
  })
  window.open(item.appUrl)
}
const gsadd = () => {
  window.location.href = gogao.value.noticeUrl
}
const tadd = (item: any) => {
  getCommon({
    monitorType: 'app',
    monitorId: item.id,
    monitorStatus: '1'
  })
  window.open(item.appUrl)
}
const gadd = () => {
  router.push('/Announcement')
}
const addurl = () => {
  window.location.href = jlobj.value.briefUrl
}
const zaddurl = () => {
  window.location.href = jlobj.value.majorUrl
}
const getgoao = async () => {
  const res = await getNotice()
  gogao.value = res.data
}
const xuejl = async () => {
  const res = await getSchoolInfo()
  jlobj.value = res.data
}
const zlbobj: any = ref()
const getSyst = async () => {
  const res = await getSystemInfo()
  setList.setsysinfo(res.data)
  xename.value = res.data.sysName
  zlbobj.value = res.data
  images.value = [
    { img: res.data.sysHeadImg },
    { img: res.data.sysHeadImg },
    { img: res.data.sysHeadImg },
    { img: res.data.sysHeadImg }
  ]
}
const zjadd = () => {
  router.push('/notify')
}
const guadd = () => {
  flags.value = !flags.value
}
const xsadd = () => {
  //跳转
  // eslint-disable-next-line no-undef
  ZWJSBridge.openLink({
    url: `https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2002182803/reserved/index.html#/subplatform?siteId=${zlbobj.value.schoolSiteid}&token=${sttokne.token}`
  }).then((res: any) => {
    console.log(res, '浙理办')
  })
}
const xueadd = () => {
  //切换学生信息
  // eslint-disable-next-line no-undef
  ZWJSBridge.openLink({
    url: `https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2002202546/reserved/index.html?appId=${store.user.user.appId}&token=${sttokne.token}&areaCode=${
      zlbobj.value.areaSiteid
    }&isIframe=true&redirectUrl=/childrenList`
  }).then((res: any) => {
    console.log(res, '浙理办')
  })
}
const qadd = () => {
  showPicker.value = true
}
const objs: any = {
  1: '学生',
  2: '教师',
  3: '家长',
  4: '社会学习者'
}
const getylist = async () => {
  const res = await getCommonService(yobj.value)
  arr.value = res.data
}
const gettjlist = async () => {
  const res = await getRecommendService(tjobj.value)
  tjarr.value = res.data
  setList.settjlist(res.data)
}
const getimgs = async () => {
  const res = await getNoticeImg({
    pageNum: 1,
    recType: 1,
    pageSize: 3
  })
  gimg.value = res.data
}
onMounted(() => {
  fieldValue.value = objs[store.user?.user.userType]
  getgoao()
  getSyst()
  getylist()
  gettjlist()
  getimgs()
  xuejl()
})
</script>

<style lang="scss" scoped>
.home-1 {
  padding-bottom: 57px;
  width: 100%;
  height: 100%;
  background: #f7f7f7;
  box-sizing: border-box;
}
.home-1-content {
  width: 100%;
  height: 190px;
  position: relative;

  margin-bottom: 162px;
}
.guanai-1 {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #fff;
  font-weight: 500;
  z-index: 99;
}
.home-1-img {
  width: 100%;
  height: 190px;
}
.home-1-co1 {
  position: absolute;
  top: 160px;
  left: 11px;
  width: 352px;
  height: 193px;
  background: #ffffff;
  border-radius: 8px;
  padding: 11px;
  border: 1px solid #e5e5e5;
  box-sizing: border-box;
}
.homes-lfti {
  position: absolute;
  top: 126px;
  left: 10px;
  display: flex;
}
.xu-1 {
  width: 100px;
  height: 22px;
  text-align: center;
  border-radius: 10px;
  opacity: 0.8;
  border: 1px solid #e5e5e5;
  background-color: #564616;
  color: #d7d6d0;
}
.xins-1 {
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  color: #fff;
}
.homes-xue {
  width: 92px;
  height: 28px;
  color: #fff;
  padding: 2px;
  line-height: 26px;
  text-align: right;
  position: absolute;
  top: 122px;
  right: 0px;
  background-image: url('../../assets/home/switch.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  box-sizing: border-box;
}
.home-1-co2 {
  width: 100%;
  height: 24px;
  font-weight: 500;
  font-size: 15px;
  color: #333333;
}
.home-1-co3 {
  width: 100%;
  height: 148px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.home-1-co4 {
  width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.home-1-co5 {
  width: 100%;
  text-align: center;
  font-weight: 400;
  font-size: 13px;
  color: #333333;
}
.imgs-1 {
  width: 40px;
  height: 40px;
}
.home-12 {
  width: 100%;
  padding: 11px 11px 0;
  box-sizing: border-box;
}
.gon-1 {
  width: 100%;
  height: 31px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.gon-1-1 {
  width: 67px;
  height: 31px;
  background-image: url('@/assets/home/tag_home_notice.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.gon-1-2 {
  width: 270px;
  height: 19px;
  white-space: nowrap; /* 防止文本换行 */
  overflow: hidden; /* 溢出隐藏 */
  text-overflow: ellipsis; /* 使用省略号显示截断的文本 */
}
.home-banner {
  width: 100%;
  height: 100px;
  box-sizing: border-box;
  margin-top: 11px;
  img {
    width: 100%;
    height: 100%;
  }
}
.xue-1 {
  width: 100%;
  height: 94px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 11px;
}
.xue-12 {
  width: 170px;
  height: 94px;
  border: 1px solid #e5e5e5;
  padding: 11px;
  border-radius: 8px;
  box-sizing: border-box;
}
.pg-1 {
  background-image: url('../../assets/home/bg_campusintroduction.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.pg-2 {
  background-image: url('../../assets/home/bg_professionalintroduction.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.x-1 {
  font-weight: 500;
  font-size: 15px;
  color: #333333;
}
.x-2 {
  font-weight: 400;
  font-size: 11px;
  color: #777777;
}
.tuijian-1 {
  width: 100%;
  height: 210px;
  background: #ffffff;
  border-radius: 8px;
  margin-top: 11px;
  padding: 11px;
  border: 1px solid #e5e5e5;
  box-sizing: border-box;
}
.t-1 {
  width: 100%;
  height: 44px;
  font-weight: 500;
  font-size: 15px;
  color: #333333;
}
.t-2 {
  width: 100%;
  height: 73px;
  background: #f5f6fa;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.te-1 {
  margin-left: 5px;
}
.te-2 {
  font-weight: 400;
  font-size: 15px;
  color: #333333;
}
.te-3 {
  font-weight: 400;
  font-size: 12px;
  color: #777777;
}
.img-1s {
  width: 40px;
  height: 40px;
  margin-right: 10px;
}
iframe {
  width: 100%;
  height: 100%; /* 确保 iframe 高度撑满父级 */
  border: none; /* 如果需要，移除 iframe 的边框 */
}
.iocs {
  font-size: 16px;
}
</style>
